package com.social.service.impl;


import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import com.social.dao.EvaluateDao;
import com.social.pojo.Evaluate;
import com.social.pojo.Petition;
import com.social.pojo.Result;
import com.social.service.EvaluateService;
import com.social.utils.UserHolder;
import org.springframework.stereotype.Service;

import javax.annotation.Resource;
import java.util.List;

/**
* @author zero
* @description 针对表【evaluate】的数据库操作Service实现
*/
@Service
public class EvaluateServiceImpl extends ServiceImpl<EvaluateDao, Evaluate>
implements EvaluateService {

    @Resource
    private EvaluateDao evaluateDao;

    @Override
    public Result addEvaluate(Evaluate evaluate) {
        Long id = UserHolder.getUser().getId();
        evaluate.setUserId(id);
        boolean save = save(evaluate);
        if(save){
            return Result.ok(200);
        }
        return  Result.fail(201,"评价失败");
    }

    @Override
    public Result findHistory() {
        Long id = UserHolder.getUser().getId();
        QueryWrapper<Evaluate> wrapper = new QueryWrapper<>();
        if(id != null){
            wrapper.eq("user_id",id);
        }
        List<Evaluate> evaluates = evaluateDao.selectList(wrapper);
        if(evaluates != null){
            return Result.ok(200,evaluates);
        }
        return Result.fail(201,"没有历史评价");
    }

    @Override
    public Result findNoEval() {
        Long id = UserHolder.getUser().getId();
        //查询信访表本人的信访
        List<Petition> list = evaluateDao.findNoEvalInPe(id);
        if(list != null){
            return Result.ok(200,list);
        }
        return Result.fail(201,"没有没评价的信访");
    }
}
